package day_15.homework;

import java.util.ArrayList;
import java.util.Random;

/**
 * @author ck
 * @date 2021/8/24 17:06
 */
public class rukou implements Runnable {
    private int people = 100;
    private final String str = "车轲";
    int a = 0;
    int b = 0;

    @Override
    public void run() {

        ArrayList<Integer> list = new ArrayList<>();

        Random r = new Random();

        while (true) {

            synchronized (str) {
                if (!(people <=0)) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    for (int j = 0; j < 7; j++) {
                        if (j == 6) {
                            int Blue = r.nextInt(16) + 1;
                            list.add(Blue);
                        } else {
                            int Red = r.nextInt(33) + 1;
                            list.add(Red);
                        }
                    }
                    people--;
                    System.out.println("编号为" + (100 - people) + "的员工 从" + Thread.currentThread().getName() + "入场！ 拿到的双色球彩票号码是：" + list);

                    list.clear();

                    if ("后门".equals(Thread.currentThread().getName())) {
                        a++;
                    }
                    if ("前门".equals(Thread.currentThread().getName())) {
                        b++;
                    }
                    if (people==0){
                        System.out.println("后门入场的员工一共"+a+"名员工");
                        System.out.println("前门入场的员工一共"+b+"名员工");
                    }
                }else{

                    break;
                }
            }

        }
    }
}

